import "package:flutter/material.dart";
import "../type.dart";

// 相关内容
class DynamicRelevantItemWidget extends StatelessWidget {
  final DynamicRelevant dynamicRelevant;
  const DynamicRelevantItemWidget({
    super.key,
    required this.dynamicRelevant,
  });
  @override
  Widget build(BuildContext context) {
    String type = dynamicRelevant.type;
    DynamicRelevantGame? dynamicRelevantGame =
        dynamicRelevant.dynamicRelevantGame;
    return Container(
      width: double.infinity,
      padding: const EdgeInsets.only(left: 10, right: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          const Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Icon(
                Icons.control_camera,
                size: 16,
                color: Colors.black38,
              ),
              Padding(
                padding: EdgeInsets.only(left: 4),
                child: Text(
                  '相关游戏',
                  style: TextStyle(
                    fontSize: 12,
                    color: Colors.black38,
                  ),
                ),
              )
            ],
          ),
         type == 'game' && dynamicRelevantGame != null
              ? Container(
                  padding: const EdgeInsets.fromLTRB(8, 8, 12, 8),
                  margin: const EdgeInsets.only(top: 4, bottom: 4),
                  decoration: BoxDecoration(
                    color: const Color.fromARGB(255, 243, 243, 244),
                    borderRadius: BorderRadius.circular(4),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Expanded(
                        flex: 1,
                        child: Padding(
                          padding: const EdgeInsets.only(right: 10),
                          child: IntrinsicHeight(
                            child: Row(
                              children: [
                                Padding(
                                  padding: const EdgeInsets.only(right: 8),
                                  child: ClipRRect(
                                    borderRadius: BorderRadius.circular(16),
                                    child: Image.asset(
                                      dynamicRelevantGame.coverUrl,
                                      width: 64,
                                      height: 64,
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                                ),
                                Expanded(
                                  flex: 1,
                                  child: Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceBetween,
                                    children: [
                                      Text(dynamicRelevantGame.title),
                                      Text(
                                        dynamicRelevantGame.type,
                                        style: const TextStyle(
                                          color: Colors.black38,
                                          fontSize: 12,
                                        ),
                                      ),
                                      Text(
                                        dynamicRelevantGame.subTitle,
                                        style: const TextStyle(
                                          color: Colors.black38,
                                          fontSize: 12,
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                      ),
                      Container(
                        padding: const EdgeInsets.only(
                            left: 12, right: 12, top: 1, bottom: 1),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(4),
                          border: Border.all(
                            width: 1,
                            color: const Color.fromARGB(255, 255, 137, 176),
                          ),
                        ),
                        child: const Text(
                          '打开',
                          style: TextStyle(
                            color: Color.fromARGB(255, 255, 137, 176),
                          ),
                        ),
                      )
                    ],
                  ),
                )
              : const SizedBox.shrink()
        ],
      ),
    );
  }
}
